<?php

namespace App\Models\client;

use App\Models\admin\Application;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Platform extends Model
{
    use HasFactory;
    use SoftDeletes;

    protected $table = 'admin_platform';

    public $fillable = [
        'user_id', 'app_id', 'number', 'logo', 'name', 'category', 'remark', 'version',  'encrypt_string', 'token', 'status', 'is_lifespan', 'start_time', 'end_time', 'status',
    ];

    /**
     * 为 array / JSON 序列化准备日期格式
     */
    protected function serializeDate(DateTimeInterface $date): string
    {
        return $date->format('Y-m-d H:i:s');
    }

    /**
     * 关联应用
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function hasApplication()
    {
        return $this->hasOne(Application::class, 'id', 'app_id');
    }
}
